package day01;

/**
 * @Author Stringzhua
 * @Date 2024/10/28 17:21
 * description:线程的插队
 */
public class Test07 {
    public static void main(String[] args) {
//        Thread mainThread = Thread.currentThread();
//        mainThread.setName("main主线程");

        System.out.println(Thread.currentThread().getName() + "主线程启动...");
        // 创建子线程：打印数字1-26
        Thread thread1 = new Thread("数字线程") {
            @Override
            public void run() {
                for (int i = 1; i <= 26; i++) {
                    System.out.println(Thread.currentThread().getName() + "打印=>" + i + "[" + Thread.currentThread().getPriority() + "]");
                }
            }
        };

        // 创建子线程：打印字母A-Z
        Thread thread2 = new Thread("字母线程") {
            @Override
            public void run() {
                for (char i = 'A'; i <= 'Z'; i++) {
                    System.out.println(Thread.currentThread().getName() + "打印=>" + i + "[" + Thread.currentThread().getPriority() + "]");
                }
            }
        };
        // 启动子线程
        thread1.start();
        thread2.start();

        try {
            //子线程插队到main线程之前执行
            thread1.join();
            thread2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println(Thread.currentThread().getName() + "主线程结束...");
    }
}
